/**
 * Created by liaoweiping on 2016/12/26.
 * 我的报价--详情
 */
import React from 'react';
import {Link,hashHistory} from 'react-router';

import Headers from '../../components/qoute/Headers';
import TipsCommon from '../../components/qoute/TipsCommon';
import Global from '../../actions/Global';
var filemgt_server_url = Global.host;
var qouteIs='none';

//时间转化日期函数
function dateFun(time){
	var date=new Date(time),message,month,day;
		month=(date.getMonth()<9)?('0'+date.getMonth()):(date.getMonth()+1);
		day=(date.getDate()<10)?('0'+date.getDate()):date.getDate();
		message=date.getFullYear()+'-'+month+'-'+day;		
		return message;
}

var QuoteDetail = React.createClass({
	getInitialState: function() {
		return {
		  	data:null,
    		qouteShow:'none',
    		commonShow:'none',//是否显示提示框
            commonContent:''//提示框内容
		};
    },
	handleClick:function(){
		 //ajax请求撤销报价接口
		var param = {
			vendorListPriceId:this.props.params.id
		};
		$.ajax({
			type: 'post',
			url: filemgt_server_url+'/purchase/cancleListPrice',
			data: JSON.stringify(param),
			dataType: 'json',
			contentType:'application/json;charset=utf-8',
			success: function(data){
				if(data.errorCode==0){			    	
			    	this.setState({qouteShow:'block'});			     
			    }else{
			    	this.setState({commonShow: 'block',commonContent:data.errorMsg});
				    setTimeout(function(){
						this.setState({ commonShow:'none',commonContent:''});
					}.bind(this),500);
			    }
			}.bind(this),
			error:function(){				
			    this.setState({commonShow: 'block',commonContent:'网络连接不上，请稍后再试'});
			    setTimeout(function(){
					this.setState({ commonShow:'none',commonContent:''});
				}.bind(this),500);
			}.bind(this)
		});
	},
	componentDidMount: function() {
        //ajax请求我的报价详情接口
		var param = {
			vendorListPriceId:this.props.params.id
		};
		$.ajax({
			type: 'post',
			url: filemgt_server_url+'/purchase/queryListPriceDetail',
			data: JSON.stringify(param),
			dataType: 'json',
			contentType:'application/json;charset=utf-8',
			success: function(data){
				if(data.errorCode==0){
			    	if(data.data==null){
				 		return false;
			    	}else{
			    		this.setState({data:data.data});
			    		qouteIs=(this.state.data.listpriceStatus=='C')?'block':'none';
						setTimeout(function(){
							this.setState({qouteShow:qouteIs});
						}.bind(this),500);
			    	}			     
			    }else{
			    	this.setState({commonShow: 'block',commonContent:data.errorMsg});
				    setTimeout(function(){
						this.setState({ commonShow:'none',commonContent:''});
					}.bind(this),500);
			    }			    
			}.bind(this),
			error:function(){
				this.setState({commonShow: 'block',commonContent:'网络连接不上，请稍后再试'});
			    setTimeout(function(){
					this.setState({ commonShow:'none',commonContent:''});
				}.bind(this),500);			 				  
			}.bind(this)
		});
	},
 	render: function () {
 		var settleType;
 		if(!!this.state.data){
 			if(this.state.data.settleType=='A'){
 				settleType='寄付';
 			}else{
 				settleType='到付';
 			}			
 		}else{
 			settleType='';
 		}
	    return (
	      <div className='full'>
	        <Headers title='我的报价'/>
	        <div className='qouteDetail'>      
	          	<h3>发布时间:{dateFun(this.state.data?this.state.data.orderDate:'')}<span className='qouteDetail-cancle' style={{display:this.state.qouteShow}}>已撤销</span></h3>
	          	<ul>
	          		<li>报价商品<span>{this.state.data?this.state.data.goodsName:''}</span></li>
	          		<li>规格<span>{this.state.data?this.state.data.goodsSpec:''}</span></li>
	          		<li>包装<span>{this.state.data?this.state.data.goodsPacking:''}</span></li>
	          		<li>单价<span>{this.state.data?this.state.data.buyPrice:''}</span></li>
	          		<li>供应量<span>{this.state.data?this.state.data.orderQty:''}</span></li>
	          		<li>供应时间<span>{this.state.data?this.state.data.supplyTime:''}</span></li>
	          		<li>联系电话<span>{this.state.data?this.state.data.phoneNumber:''}</span></li>
	          		<li>发货地址<span>{this.state.data?this.state.data.sendAddr:''}</span></li>
	          		<li>物流方式<span>{settleType}</span></li>
	          		<li className='qouteDetail-des'>果品描述<span>{this.state.data?this.state.data.goodsDesc:''}</span></li>
	          	</ul>	          	
	        </div> 
	        <div className='qouteDetail-img'>
	       		<h3>图片说明</h3>
	       		<img src=''/>
	        </div>
	        <div className='sumbitBtn' style={{display:this.state.qouteShow=='none'?'block':'none'}}>
	           <a onClick={this.handleClick}>撤销报价</a>
	        </div>
	        <TipsCommon isShow={this.state.commonShow} content={this.state.commonContent}/>
	      </div>
	    )
  	}
});
export default QuoteDetail;
